package com.yy.permissions_general.security.handler;

import com.yy.permissions_general.utils.encrypt.AESUtil;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * @program: permissions_general
 * @description: 自定义加密器
 * @author: YY
 * @create: 2021-11-06 19:01
 **/
@Component
public class MyPasswordEncoderHandler implements PasswordEncoder {
    /**
     * 对密码进行加密并返回
     */
    @Override
    public String encode(CharSequence rawPassword) {
        String encPassword = null;
        try {
            encPassword = AESUtil.aesEncrypt(rawPassword.toString(),AESUtil.KEY_STR);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return encPassword;
    }
    /**
     * 验证密码是否正确
     */
    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
         return encode(rawPassword).equals(encodedPassword);
    }
}
